﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;

namespace OpenCube.Nbt.Mapping.Attributes
{
	[AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = false)]
	public sealed class NbtNameAttribute
		: NbtAttribute
	{
		private readonly IReadOnlyList<string> _names;

		public NbtNameAttribute(string name)
			: this(name, null)
		{
		}

		public NbtNameAttribute(string name, params string[] nameTwoAndMore)
		{
			var names = new List<string>();

			names.Add(name);

			if (nameTwoAndMore != null)
				names.AddRange(nameTwoAndMore);

			if (names.Count != names.Distinct().Count())
				throw new ArgumentException("All names should be unique");

			_names = new ReadOnlyCollection<string>(names);
		}

		/// <summary>
		/// Gets the names of the NBT Tags.
		/// </summary>
		public IReadOnlyList<string> Names
		{
			get { return _names; }
		}
	}
}